﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class TransactionCategoriesDBAccess
    {
        /// <summary>
        /// Insert TransactionCategories
        /// </summary>
        /// <param name="objTransactionCategories"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>

        public bool AddNewTransactionCategories(TransactionCategories objTransactionCategories, String CONNECTION_STRING)
        {
            SqlParameter[] parameter = new SqlParameter[]
            {
               // new SqlParameter("@CardTypeID", objCardType.CardTypeID),
                new SqlParameter("@Created", objTransactionCategories.Created),
                new SqlParameter("@Updated", objTransactionCategories.Updated),
                new SqlParameter("@Isactive", objTransactionCategories.Isactive),
                new SqlParameter("@Name", objTransactionCategories.Name),
                new SqlParameter("@Descriptions", objTransactionCategories.Descriptions),
                new SqlParameter("@SearchKey", objTransactionCategories.SearchKey),
            };
            return SqlDBHelper.ExecuteNonQuery("AddNewTransactionCategories", CommandType.StoredProcedure, CONNECTION_STRING, parameter);
        }

        /// <summary>
        /// Update TransactionCategories
        /// </summary>
        /// <param name="objTransactionCategories"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public bool UpdateTransactionCategories(TransactionCategories objTransactionCategories, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                //new SqlParameter("@CardTypeID", objCardType.CardTypeID),
                new SqlParameter("@Created", objTransactionCategories.Created),
                new SqlParameter("@Updated", objTransactionCategories.Updated),
                new SqlParameter("@Isactive", objTransactionCategories.Isactive),
                new SqlParameter("@Name", objTransactionCategories.Name),
                new SqlParameter("@Descriptions", objTransactionCategories.Descriptions),
                new SqlParameter("@SearchKey", objTransactionCategories.SearchKey),
            };

            return SqlDBHelper.ExecuteNonQuery("UpdateTransactionCategories", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
        }

        /// <summary>
        /// Delete TransactionCategories
        /// </summary>
        /// <param name="TransactionCategoriesID"></param>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public bool DeleteTransactionCategories(int TransactionCategoriesID, String CONNECTION_STRING)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@TransactionCategoriesID", TransactionCategoriesID)
            };

            return SqlDBHelper.ExecuteNonQuery("DeleteTransactionCategories", CommandType.StoredProcedure, CONNECTION_STRING, parameters);
        }

        /// <summary>
        /// Get TransactionCategories Details
        /// </summary>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public DataTable GetTransactionCategoriesTable(String CONNECTION_STRING)
        {
            
            //Lets get the list of all Non Term Current in a datataable
            DataTable table = SqlDBHelper.ExecuteSelectCommand("GetTransactionCategoriesTable", CommandType.StoredProcedure, CONNECTION_STRING);
            return table;
        }

        /// <summary>
        /// Get TransactionCategories List
        /// </summary>
        /// <param name="CONNECTION_STRING"></param>
        /// <returns></returns>
        public List<TransactionCategories> GetTransactionCategoriesList(String CONNECTION_STRING)
        {
            List<TransactionCategories> litTransactionCategories = null;

            //Lets get the list of all TransactionCategories in a datataable
            using (DataTable table = SqlDBHelper.ExecuteSelectCommand("GetTransactionCategoriesList", CommandType.StoredProcedure, CONNECTION_STRING))
            {
                //check if any record exist or not
                if (table.Rows.Count > 0)
                {
                    //Lets go ahead and create the list of TransactionCategories
                    litTransactionCategories = new List<TransactionCategories>();

                    //Now lets populate TransactionCategories details into the list of TransactionCategories
                    foreach (DataRow row in table.Rows)
                    {
                        TransactionCategories objTransactionCategories = new TransactionCategories();
                        objTransactionCategories.TransactionCategoriesID = Convert.ToInt32(row["TransactionCategoriesID"]);
                        objTransactionCategories.Created = row["Created"].ToString();
                        objTransactionCategories.Updated = row["Updated"].ToString();
                        objTransactionCategories.Isactive = row["Isactive"].ToString();
                        objTransactionCategories.Name = row["Name"].ToString();
                        objTransactionCategories.Descriptions = row["Descriptions"].ToString();
                        objTransactionCategories.SearchKey = row["SearchKey"].ToString();

                        litTransactionCategories.Add(objTransactionCategories);
                    }
                }
            }

            return litTransactionCategories;
        }        
    }
}
